/**
 * Copyright (c) 2011 - 2012, Sohu Inc. All rights reserved.
 * @fileoverview Sohu  搜索框部分交互功能(需嵌套模板使用)
 * @author  wangxin | xinwang200110@sohu-inc.com
 * @version 1.0 | 2013-04-17
 * @param
 * @example
 */

LJS.define('cpt.search',function(ljs){
	var that = {};
	that.addEvent = function(){
		
		that.input.on('focus',function(){
			if(that.input[0].value == that.input.attr('defValue')){
				that.input[0].value = '';
			}
		});
		
		that.input.on('blur',function(){
			if(that.input[0].value == ''){
				that.input[0].value = that.input.attr('defValue');
			}
		});
		
		that.delBtn.on('click',function(){
			that.input[0].value = '';
			that.input[0].focus();
		});
		that.searchBtn.on('click',function(){
			if(that.input[0].value == that.input.attr('defValue')){
				that.input[0].value = '';
			}
			$(this).parent('form').submit()
		})
	}
	that.init = function(){
		that.input = $('#searchInput');
		that.delBtn = $('#del');
		that.searchBtn = $('#searchId');
		that.addEvent();
	}
	return that;
});
